import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:load_switch/load_switch.dart';

class SwitchX extends StatelessWidget {
  final bool value;
  final double width;
  final double height;
  final bool? isLoading;
  final dynamic Function(bool) onTap;
  final Future<bool> Function() future;
  final bool enable;
  const SwitchX(
      {super.key,
      required this.value,
      this.width = 64,
      this.height = 32,
      this.isLoading,
      required this.onTap,
      required this.future, this.enable = true});

  @override
  Widget build(BuildContext context) {
    return LoadSwitch(
      height: height,
      width: width,
      value: value,
      future: future,
      style: SpinStyle.material,
      thumbSizeRatio: 0.9,
      switchDecoration: (bool value, bool isActive) {
        return BoxDecoration(
            borderRadius: BorderRadius.circular(16),
            color: value ? Get.theme.primaryColor : Color(0xfff1f1f1));
      },
      isLoading: isLoading,
      onChange: (v) {},
      isActive: enable,
      onTap: onTap,
      onError: (e){
        printError(info: "SwitchX error:$e");
      },
    );
  }
}
